﻿using System;
using System.Collections.Generic;
using UltimateFracturing;
using UnityEngine;

// Token: 0x0200042D RID: 1069
[ExecuteInEditMode]
public class FracturedObject : MonoBehaviour
{
	// Token: 0x17000442 RID: 1090
	// (get) Token: 0x06001E24 RID: 7716 RVA: 0x000BF787 File Offset: 0x000BD987
	// (set) Token: 0x06001E25 RID: 7717 RVA: 0x000BF7B5 File Offset: 0x000BD9B5
	public Material GizmosMaterial
	{
		get
		{
			if (this.m_GizmosMaterial == null)
			{
				this.m_GizmosMaterial = new Material(Shader.Find("Unlit/FracturingColored"));
			}
			return this.m_GizmosMaterial;
		}
		set
		{
			this.m_GizmosMaterial = value;
		}
	}

	// Token: 0x06001E26 RID: 7718 RVA: 0x00002973 File Offset: 0x00000B73
	private void Awake()
	{
	}

	// Token: 0x06001E27 RID: 7719 RVA: 0x000BF7C0 File Offset: 0x000BD9C0
	private void Start()
	{
		this.m_bCheckDetachNonSupportedChunkds = false;
		this.m_bExploded = false;
		this.m_bDetached = false;
		if (Application.isPlaying)
		{
			this.SetSingleMeshVisibility(true);
			if (!this.StartStatic)
			{
				Rigidbody component = base.GetComponent<Rigidbody>();
				if (component != null && !component.isKinematic)
				{
					base.gameObject.AddComponent<CheckDynamicCollision>();
				}
				else
				{
					this.CheckDetachNonSupportedChunks(true);
				}
			}
			else
			{
				Rigidbody component2 = base.GetComponent<Rigidbody>();
				if (component2 != null && !component2.isKinematic)
				{
					Debug.LogWarning("Fracturable Object " + base.gameObject.name + " has a dynamic rigidbody but parameter Start Static is checked. Start static will be ignored.");
					base.gameObject.AddComponent<CheckDynamicCollision>();
				}
			}
			this.m_afFreeChunkSoundTimers = new float[Mathf.Max(0, this.EventDetachedMaxSounds)];
			this.m_afFreeChunkPrefabTimers = new float[Mathf.Max(0, this.EventDetachedMaxPrefabs)];
		}
	}

	// Token: 0x06001E28 RID: 7720 RVA: 0x000BF8B0 File Offset: 0x000BDAB0
	private void Update()
	{
		if (Application.isPlaying)
		{
			if (this.m_bCheckDetachNonSupportedChunkds)
			{
				this.CheckDetachNonSupportedChunksInternal(false);
				this.m_bCheckDetachNonSupportedChunkds = false;
			}
			if (this.m_afFreeChunkSoundTimers.Length != this.EventDetachedMaxSounds)
			{
				Array.Resize<float>(ref this.m_afFreeChunkSoundTimers, this.EventDetachedMaxSounds);
			}
			if (this.m_afFreeChunkPrefabTimers.Length != this.EventDetachedMaxPrefabs)
			{
				Array.Resize<float>(ref this.m_afFreeChunkPrefabTimers, this.EventDetachedMaxPrefabs);
			}
			for (int i = 0; i < this.m_afFreeChunkSoundTimers.Length; i++)
			{
				if (this.m_afFreeChunkSoundTimers[i] >= 0f)
				{
					this.m_afFreeChunkSoundTimers[i] -= Time.deltaTime;
				}
			}
			for (int j = 0; j < this.m_afFreeChunkPrefabTimers.Length; j++)
			{
				if (this.m_afFreeChunkPrefabTimers[j] >= 0f)
				{
					this.m_afFreeChunkPrefabTimers[j] -= Time.deltaTime;
				}
			}
		}
	}

	// Token: 0x06001E29 RID: 7721 RVA: 0x00002973 File Offset: 0x00000B73
	private void OnRenderObject()
	{
	}

	// Token: 0x06001E2A RID: 7722 RVA: 0x000BF9A8 File Offset: 0x000BDBA8
	public void OnCreateFracturedObject()
	{
		this.m_bCheckDetachNonSupportedChunkds = false;
		this.m_bExploded = false;
		this.m_bDetached = false;
		this.IsUsingSingleMeshObjectDraw = true;
		if (Application.isPlaying)
		{
			if (!this.StartStatic)
			{
				this.CheckDetachNonSupportedChunks(true);
			}
			this.m_afFreeChunkSoundTimers = new float[Mathf.Max(0, this.EventDetachedMaxSounds)];
			this.m_afFreeChunkPrefabTimers = new float[Mathf.Max(0, this.EventDetachedMaxPrefabs)];
		}
	}

	// Token: 0x06001E2B RID: 7723 RVA: 0x000BFA1C File Offset: 0x000BDC1C
	public void SetSingleMeshVisibility(bool bEnabled)
	{
		if (this.SingleMeshObject == null)
		{
			return;
		}
		if (this.IsUsingSingleMeshObjectDraw == bEnabled)
		{
			return;
		}
		this.SingleMeshObject.GetComponent<Renderer>().enabled = bEnabled;
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.GetComponent<Renderer>().enabled = !bEnabled;
			}
		}
		this.IsUsingSingleMeshObjectDraw = bEnabled;
	}

	// Token: 0x06001E2C RID: 7724 RVA: 0x000BFAC4 File Offset: 0x000BDCC4
	public bool ResetChunks()
	{
		foreach (FracturedChunk x in this.ListFracturedChunks)
		{
			if (x == null)
			{
				return false;
			}
		}
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			fracturedChunk.ResetChunk(this);
		}
		if (!this.StartStatic)
		{
			this.CheckDetachNonSupportedChunks(true);
		}
		this.SetSingleMeshVisibility(true);
		this.m_bDetached = false;
		this.m_bExploded = false;
		return true;
	}

	// Token: 0x06001E2D RID: 7725 RVA: 0x000BFBA4 File Offset: 0x000BDDA4
	public List<FracturedChunk> GetDestructibleChunksInRadius(Vector3 v3Position, float fRadius, bool bAlsoIncludeFreeChunks)
	{
		List<FracturedChunk> list = new List<FracturedChunk>();
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				bool flag = bAlsoIncludeFreeChunks || !fracturedChunk.IsDetachedChunk;
				if (flag && fracturedChunk.IsDestructibleChunk() && Vector3.Distance(fracturedChunk.transform.position, v3Position) < fRadius)
				{
					list.Add(fracturedChunk);
				}
			}
		}
		return list;
	}

	// Token: 0x06001E2E RID: 7726 RVA: 0x000BFC50 File Offset: 0x000BDE50
	public void Explode(Vector3 v3ExplosionPosition, float fExplosionForce)
	{
		if (this.m_bExploded)
		{
			return;
		}
		if (this.EventExplosionSound)
		{
			AudioSource.PlayClipAtPoint(this.EventExplosionSound, v3ExplosionPosition);
		}
		if (this.EventExplosionPrefabsArray.Length > 0 && this.EventExplosionPrefabsInstanceCount > 0 && this.ListFracturedChunks.Count > 0)
		{
			for (int i = 0; i < this.EventExplosionPrefabsInstanceCount; i++)
			{
				FracturedObject.PrefabInfo prefabInfo = this.EventExplosionPrefabsArray[UnityEngine.Random.Range(0, this.EventExplosionPrefabsArray.Length)];
				if (prefabInfo != null)
				{
					FracturedChunk fracturedChunk = null;
					while (fracturedChunk == null)
					{
						fracturedChunk = this.ListFracturedChunks[UnityEngine.Random.Range(0, this.ListFracturedChunks.Count)];
					}
					GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefabInfo.GameObject, fracturedChunk.transform.position, prefabInfo.GameObject.transform.rotation);
					if (!Mathf.Approximately(prefabInfo.MinLifeTime, 0f) || !Mathf.Approximately(prefabInfo.MaxLifeTime, 0f))
					{
						DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
						dieTimer.SecondsToDie = UnityEngine.Random.Range(prefabInfo.MinLifeTime, prefabInfo.MaxLifeTime);
					}
				}
			}
		}
		foreach (FracturedChunk fracturedChunk2 in this.ListFracturedChunks)
		{
			if (fracturedChunk2)
			{
				fracturedChunk2.ListAdjacentChunks.Clear();
				if (fracturedChunk2.IsDestructibleChunk() && !fracturedChunk2.IsDetachedChunk)
				{
					fracturedChunk2.DetachFromObject(false);
					fracturedChunk2.GetComponent<Rigidbody>().AddExplosionForce(fExplosionForce, v3ExplosionPosition, 0f, 0f);
				}
			}
		}
		this.m_bExploded = true;
	}

	// Token: 0x06001E2F RID: 7727 RVA: 0x000BFE28 File Offset: 0x000BE028
	public void Explode(Vector3 v3ExplosionPosition, float fExplosionForce, float fRadius, bool bPlayExplosionSound, bool bInstanceExplosionPrefabs, bool bAlsoExplodeFree, bool bCheckStructureIntegrityAfter)
	{
		List<FracturedChunk> list = new List<FracturedChunk>();
		if (this.EventExplosionSound && bPlayExplosionSound)
		{
			AudioSource.PlayClipAtPoint(this.EventExplosionSound, v3ExplosionPosition);
		}
		foreach (FracturedChunk fracturedChunk in this.GetDestructibleChunksInRadius(v3ExplosionPosition, fRadius, bAlsoExplodeFree))
		{
			if (fracturedChunk)
			{
				fracturedChunk.DetachFromObject(false);
				fracturedChunk.GetComponent<Rigidbody>().AddExplosionForce(fExplosionForce, v3ExplosionPosition, 0f, 0f);
				list.Add(fracturedChunk);
			}
		}
		if (bInstanceExplosionPrefabs && this.EventExplosionPrefabsArray.Length > 0 && this.EventExplosionPrefabsInstanceCount > 0 && list.Count > 0)
		{
			for (int i = 0; i < Mathf.Max(this.EventExplosionPrefabsInstanceCount, list.Count); i++)
			{
				FracturedObject.PrefabInfo prefabInfo = this.EventExplosionPrefabsArray[UnityEngine.Random.Range(0, this.EventExplosionPrefabsArray.Length)];
				if (prefabInfo != null)
				{
					GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefabInfo.GameObject, list[UnityEngine.Random.Range(0, list.Count)].transform.position, prefabInfo.GameObject.transform.rotation);
					if (!Mathf.Approximately(prefabInfo.MinLifeTime, 0f) || !Mathf.Approximately(prefabInfo.MaxLifeTime, 0f))
					{
						DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
						dieTimer.SecondsToDie = UnityEngine.Random.Range(prefabInfo.MinLifeTime, prefabInfo.MaxLifeTime);
					}
				}
			}
		}
		if (bCheckStructureIntegrityAfter)
		{
			this.CheckDetachNonSupportedChunks(false);
		}
	}

	// Token: 0x06001E30 RID: 7728 RVA: 0x000BFFE0 File Offset: 0x000BE1E0
	public void DeleteChunks()
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				UnityEngine.Object.DestroyImmediate(fracturedChunk.gameObject);
			}
		}
		this.ListFracturedChunks.Clear();
		if (this.SingleMeshObject)
		{
			UnityEngine.Object.DestroyImmediate(this.SingleMeshObject);
		}
	}

	// Token: 0x06001E31 RID: 7729 RVA: 0x000C0074 File Offset: 0x000BE274
	public void CollapseChunks()
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.ListAdjacentChunks.Clear();
				if (fracturedChunk.IsDestructibleChunk() && !fracturedChunk.IsDetachedChunk)
				{
					fracturedChunk.DetachFromObject(false);
				}
			}
		}
	}

	// Token: 0x06001E32 RID: 7730 RVA: 0x000C00FC File Offset: 0x000BE2FC
	public void ExplodeChunks(float fExplosionForce, Vector3 v3ExplosionPosition, float fUpwardsModifier)
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.ListAdjacentChunks.Clear();
				if (fracturedChunk.IsDestructibleChunk() && !fracturedChunk.IsDetachedChunk)
				{
					fracturedChunk.DetachFromObject(false);
					fracturedChunk.GetComponent<Rigidbody>().AddExplosionForce(fExplosionForce, v3ExplosionPosition, 0f, fUpwardsModifier);
				}
			}
		}
	}

	// Token: 0x06001E33 RID: 7731 RVA: 0x000C0198 File Offset: 0x000BE398
	public void ComputeChunksRelativeVolume()
	{
		float num = 0f;
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				MeshFilter component = fracturedChunk.GetComponent<MeshFilter>();
				if (component)
				{
					num += component.sharedMesh.bounds.size.x * component.sharedMesh.bounds.size.y * component.sharedMesh.bounds.size.z;
				}
			}
		}
		foreach (FracturedChunk fracturedChunk2 in this.ListFracturedChunks)
		{
			if (fracturedChunk2)
			{
				MeshFilter component2 = fracturedChunk2.GetComponent<MeshFilter>();
				if (component2)
				{
					float num2 = component2.sharedMesh.bounds.size.x * component2.sharedMesh.bounds.size.y * component2.sharedMesh.bounds.size.z;
					fracturedChunk2.RelativeVolume = num2 / num;
					fracturedChunk2.Volume = num2;
				}
			}
		}
	}

	// Token: 0x06001E34 RID: 7732 RVA: 0x000C0348 File Offset: 0x000BE548
	public void ComputeChunksMass(float fTotalMass)
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk && fracturedChunk.GetComponent<Rigidbody>())
			{
				float num = fTotalMass * fracturedChunk.RelativeVolume;
				if (num < 0.001f)
				{
					num = 0.001f;
				}
				fracturedChunk.GetComponent<Rigidbody>().mass = num;
			}
		}
	}

	// Token: 0x06001E35 RID: 7733 RVA: 0x000C03E0 File Offset: 0x000BE5E0
	public bool HasDetachedChunks()
	{
		return this.m_bDetached;
	}

	// Token: 0x06001E36 RID: 7734 RVA: 0x000C03E8 File Offset: 0x000BE5E8
	public void NotifyChunkDetach(FracturedChunk chunk)
	{
		if (!this.m_bDetached)
		{
			foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
			{
				if (fracturedChunk != null)
				{
					Collider component = fracturedChunk.GetComponent<Collider>();
					if (component != null)
					{
						component.isTrigger = false;
					}
				}
			}
		}
		this.m_bDetached = true;
		this.SetSingleMeshVisibility(false);
		if (this.EventDetachedAnyCallMethod.Length > 0 && this.EventDetachedAnyCallGameObject != null)
		{
			this.EventDetachedAnyCallGameObject.SendMessage(this.EventDetachedAnyCallMethod);
		}
	}

	// Token: 0x06001E37 RID: 7735 RVA: 0x000C04B0 File Offset: 0x000BE6B0
	public void NotifyDetachChunkCollision(FracturedChunk.CollisionInfo collisionInfo)
	{
		if (this.EventDetachCollisionCallGameObject != null && this.EventDetachCollisionCallMethod.Length > 0)
		{
			this.EventDetachCollisionCallGameObject.SendMessage(this.EventDetachCollisionCallMethod, collisionInfo);
		}
		if (!collisionInfo.bCancelCollisionEvent)
		{
			this.NotifyDetachChunkCollision(collisionInfo.collisionPoint, collisionInfo.bIsMain);
		}
	}

	// Token: 0x06001E38 RID: 7736 RVA: 0x000C0510 File Offset: 0x000BE710
	public void NotifyDetachChunkCollision(Vector3 v3Position, bool bIsMain)
	{
		if (this.EventDetachSound != null && bIsMain)
		{
			AudioSource.PlayClipAtPoint(this.EventDetachSound, v3Position);
		}
		if (this.EventDetachPrefabsArray != null && bIsMain && this.EventDetachPrefabsArray.Length > 0)
		{
			FracturedObject.PrefabInfo prefabInfo = this.EventDetachPrefabsArray[UnityEngine.Random.Range(0, this.EventDetachPrefabsArray.Length)];
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefabInfo.GameObject, v3Position, prefabInfo.GameObject.transform.rotation);
			if (!Mathf.Approximately(prefabInfo.MinLifeTime, 0f) || !Mathf.Approximately(prefabInfo.MaxLifeTime, 0f))
			{
				DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
				dieTimer.SecondsToDie = UnityEngine.Random.Range(prefabInfo.MinLifeTime, prefabInfo.MaxLifeTime);
			}
		}
	}

	// Token: 0x06001E39 RID: 7737 RVA: 0x000C05DC File Offset: 0x000BE7DC
	public void NotifyFreeChunkCollision(FracturedChunk.CollisionInfo collisionInfo)
	{
		if (this.EventDetachedCollisionCallGameObject != null && this.EventDetachedCollisionCallMethod.Length > 0)
		{
			this.EventDetachedCollisionCallGameObject.SendMessage(this.EventDetachedCollisionCallMethod, collisionInfo);
		}
		if (!collisionInfo.bCancelCollisionEvent)
		{
			if (this.EventDetachedSoundArray.Length > 0)
			{
				int num = -1;
				for (int i = 0; i < this.m_afFreeChunkSoundTimers.Length; i++)
				{
					if (this.m_afFreeChunkSoundTimers[i] <= 0f)
					{
						num = i;
						break;
					}
				}
				if (num != -1)
				{
					AudioClip audioClip = this.EventDetachedSoundArray[UnityEngine.Random.Range(0, this.EventDetachedSoundArray.Length)];
					if (audioClip != null)
					{
						AudioSource.PlayClipAtPoint(audioClip, collisionInfo.collisionPoint);
					}
					this.m_afFreeChunkSoundTimers[num] = audioClip.length;
				}
			}
			if (this.EventDetachedPrefabsArray.Length > 0)
			{
				FracturedObject.PrefabInfo prefabInfo = this.EventDetachedPrefabsArray[UnityEngine.Random.Range(0, this.EventDetachedPrefabsArray.Length)];
				if (prefabInfo != null)
				{
					int num2 = -1;
					for (int j = 0; j < this.m_afFreeChunkPrefabTimers.Length; j++)
					{
						if (this.m_afFreeChunkPrefabTimers[j] <= 0f)
						{
							num2 = j;
							break;
						}
					}
					if (num2 != -1)
					{
						GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefabInfo.GameObject, collisionInfo.collisionPoint, prefabInfo.GameObject.transform.rotation);
						if (!Mathf.Approximately(prefabInfo.MinLifeTime, 0f) || !Mathf.Approximately(prefabInfo.MaxLifeTime, 0f))
						{
							DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
							dieTimer.SecondsToDie = UnityEngine.Random.Range(prefabInfo.MinLifeTime, prefabInfo.MaxLifeTime);
							this.m_afFreeChunkPrefabTimers[num2] = dieTimer.SecondsToDie;
						}
						else
						{
							this.m_afFreeChunkPrefabTimers[num2] = float.MaxValue;
						}
					}
				}
			}
		}
	}

	// Token: 0x06001E3A RID: 7738 RVA: 0x000C07AC File Offset: 0x000BE9AC
	public void NotifyImpact(Vector3 v3Position)
	{
		if (this.EventImpactSound != null)
		{
			AudioSource.PlayClipAtPoint(this.EventImpactSound, v3Position);
		}
		if (this.EventImpactPrefabsArray != null && this.EventImpactPrefabsArray.Length > 0)
		{
			FracturedObject.PrefabInfo prefabInfo = this.EventImpactPrefabsArray[UnityEngine.Random.Range(0, this.EventImpactPrefabsArray.Length)];
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefabInfo.GameObject, v3Position, prefabInfo.GameObject.transform.rotation);
			if (!Mathf.Approximately(prefabInfo.MinLifeTime, 0f) || !Mathf.Approximately(prefabInfo.MaxLifeTime, 0f))
			{
				DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
				dieTimer.SecondsToDie = UnityEngine.Random.Range(prefabInfo.MinLifeTime, prefabInfo.MaxLifeTime);
			}
		}
	}

	// Token: 0x06001E3B RID: 7739 RVA: 0x000C086C File Offset: 0x000BEA6C
	public void ResetAllChunkVisitedFlags()
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.Visited = false;
			}
		}
	}

	// Token: 0x06001E3C RID: 7740 RVA: 0x000C08D4 File Offset: 0x000BEAD4
	public void CheckDetachNonSupportedChunks(bool bForceImmediate = false)
	{
		if (bForceImmediate)
		{
			this.CheckDetachNonSupportedChunksInternal(false);
		}
		else
		{
			this.m_bCheckDetachNonSupportedChunkds = true;
		}
	}

	// Token: 0x06001E3D RID: 7741 RVA: 0x000C08F0 File Offset: 0x000BEAF0
	public void MarkNonSupportedChunks()
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.IsNonSupportedChunk = false;
			}
		}
		this.CheckDetachNonSupportedChunksInternal(true);
	}

	// Token: 0x06001E3E RID: 7742 RVA: 0x000C0960 File Offset: 0x000BEB60
	private void CheckDetachNonSupportedChunksInternal(bool bOnlyMarkThem = false)
	{
		if (!this.GenerateChunkConnectionInfo)
		{
			return;
		}
		List<FracturedChunk> list = new List<FracturedChunk>();
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk && !fracturedChunk.IsDetachedChunk && !fracturedChunk.IsSupportChunk)
			{
				list.Add(fracturedChunk);
			}
		}
		this.ResetAllChunkVisitedFlags();
		while (list.Count > 0)
		{
			while (list.Count > 0)
			{
				if (!list[0].IsDetachedChunk)
				{
					break;
				}
				list[0].IsNonSupportedChunk = true;
				list.RemoveAt(0);
			}
			if (list.Count == 0)
			{
				break;
			}
			List<FracturedChunk> list2 = new List<FracturedChunk>();
			List<FracturedChunk> list3 = new List<FracturedChunk>();
			bool flag = FracturedObject.AreSupportedChunksRecursive(list[0], list2, list3);
			foreach (FracturedChunk item in list2)
			{
				list.Remove(item);
			}
			if (!flag)
			{
				foreach (FracturedChunk fracturedChunk2 in list2)
				{
					if (!bOnlyMarkThem)
					{
						fracturedChunk2.DetachFromObject(false);
					}
					else
					{
						fracturedChunk2.IsNonSupportedChunk = true;
					}
				}
			}
			else if ((double)this.ChunkHorizontalRadiusSupportStrength < 10000000000000000.0)
			{
				foreach (FracturedChunk fracturedChunk3 in list2)
				{
					if (!fracturedChunk3.IsSupportChunk)
					{
						float num = float.MaxValue;
						foreach (FracturedChunk fracturedChunk4 in list3)
						{
							if (fracturedChunk3 != fracturedChunk4)
							{
								Vector3 vector = fracturedChunk3.transform.position - fracturedChunk4.transform.position;
								vector = new Vector3(vector.x, 0f, vector.z);
								if (vector.magnitude < num)
								{
									num = vector.magnitude;
								}
							}
						}
						if (num > this.ChunkHorizontalRadiusSupportStrength)
						{
							if (!bOnlyMarkThem)
							{
								fracturedChunk3.DetachFromObject(false);
							}
							else
							{
								fracturedChunk3.IsNonSupportedChunk = true;
							}
						}
					}
				}
			}
		}
	}

	// Token: 0x06001E3F RID: 7743 RVA: 0x000C0C58 File Offset: 0x000BEE58
	private static bool AreSupportedChunksRecursive(FracturedChunk chunk, List<FracturedChunk> listChunksVisited, List<FracturedChunk> listChunksSupport)
	{
		if (chunk.Visited)
		{
			return false;
		}
		chunk.Visited = true;
		listChunksVisited.Add(chunk);
		if (chunk.IsSupportChunk)
		{
			listChunksSupport.Add(chunk);
		}
		bool flag = false;
		foreach (FracturedChunk.AdjacencyInfo adjacencyInfo in chunk.ListAdjacentChunks)
		{
			if (adjacencyInfo.chunk && adjacencyInfo.chunk.FracturedObjectSource && adjacencyInfo.fArea >= adjacencyInfo.chunk.FracturedObjectSource.ChunkConnectionMinArea && FracturedObject.AreSupportedChunksRecursive(adjacencyInfo.chunk, listChunksVisited, listChunksSupport))
			{
				flag = true;
			}
		}
		return chunk.IsSupportChunk || flag;
	}

	// Token: 0x06001E40 RID: 7744 RVA: 0x000C0D40 File Offset: 0x000BEF40
	public void AddSupportPlane()
	{
		if (this.ListSupportPlanes == null)
		{
			this.ListSupportPlanes = new List<SupportPlane>();
		}
		this.ListSupportPlanes.Add(new SupportPlane(this));
	}

	// Token: 0x06001E41 RID: 7745 RVA: 0x000C0D6C File Offset: 0x000BEF6C
	public void ComputeSupportPlaneIntersections()
	{
		foreach (FracturedChunk fracturedChunk in this.ListFracturedChunks)
		{
			if (fracturedChunk)
			{
				fracturedChunk.IsSupportChunk = false;
				foreach (SupportPlane supportPlane in this.ListSupportPlanes)
				{
					if (supportPlane.IntersectsWith(fracturedChunk.gameObject, true))
					{
						fracturedChunk.IsSupportChunk = true;
					}
				}
			}
		}
	}

	// Token: 0x04001E47 RID: 7751
	public bool GUIExpandMain = true;

	// Token: 0x04001E48 RID: 7752
	public GameObject SourceObject;

	// Token: 0x04001E49 RID: 7753
	public bool GenerateIslands = true;

	// Token: 0x04001E4A RID: 7754
	public bool GenerateChunkConnectionInfo = true;

	// Token: 0x04001E4B RID: 7755
	public bool StartStatic;

	// Token: 0x04001E4C RID: 7756
	public float ChunkConnectionMinArea;

	// Token: 0x04001E4D RID: 7757
	public float ChunkConnectionStrength = 0.8f;

	// Token: 0x04001E4E RID: 7758
	public float ChunkHorizontalRadiusSupportStrength = float.PositiveInfinity;

	// Token: 0x04001E4F RID: 7759
	public bool SupportChunksAreIndestructible = true;

	// Token: 0x04001E50 RID: 7760
	public float ChunkIslandConnectionMaxDistance = 0.02f;

	// Token: 0x04001E51 RID: 7761
	public float TotalMass = 10f;

	// Token: 0x04001E52 RID: 7762
	public PhysicMaterial ChunkPhysicMaterial;

	// Token: 0x04001E53 RID: 7763
	public float MinColliderVolumeForBox = 1E-05f;

	// Token: 0x04001E54 RID: 7764
	public float CapPrecisionFix;

	// Token: 0x04001E55 RID: 7765
	public bool InvertCapNormals;

	// Token: 0x04001E56 RID: 7766
	public FracturedObject.ColliderType ChunkColliderType;

	// Token: 0x04001E57 RID: 7767
	public bool GUIExpandSplits = true;

	// Token: 0x04001E58 RID: 7768
	public FracturedObject.EFracturePattern FracturePattern;

	// Token: 0x04001E59 RID: 7769
	public bool VoronoiVolumeOptimization = true;

	// Token: 0x04001E5A RID: 7770
	public bool VoronoiProximityOptimization = true;

	// Token: 0x04001E5B RID: 7771
	public bool VoronoiMultithreading = true;

	// Token: 0x04001E5C RID: 7772
	public int VoronoiCellsXCount = 3;

	// Token: 0x04001E5D RID: 7773
	public int VoronoiCellsYCount = 3;

	// Token: 0x04001E5E RID: 7774
	public int VoronoiCellsZCount = 3;

	// Token: 0x04001E5F RID: 7775
	public float VoronoiCellsXSizeVariation = 0.5f;

	// Token: 0x04001E60 RID: 7776
	public float VoronoiCellsYSizeVariation = 0.5f;

	// Token: 0x04001E61 RID: 7777
	public float VoronoiCellsZSizeVariation = 0.5f;

	// Token: 0x04001E62 RID: 7778
	public int GenerateNumChunks = 20;

	// Token: 0x04001E63 RID: 7779
	public bool SplitsWorldSpace = true;

	// Token: 0x04001E64 RID: 7780
	public bool SplitRegularly;

	// Token: 0x04001E65 RID: 7781
	public float SplitXProbability = 0.3333f;

	// Token: 0x04001E66 RID: 7782
	public float SplitYProbability = 0.3333f;

	// Token: 0x04001E67 RID: 7783
	public float SplitZProbability = 0.3333f;

	// Token: 0x04001E68 RID: 7784
	public float SplitSizeVariation;

	// Token: 0x04001E69 RID: 7785
	public float SplitXVariation = 0.6f;

	// Token: 0x04001E6A RID: 7786
	public float SplitYVariation = 0.6f;

	// Token: 0x04001E6B RID: 7787
	public float SplitZVariation = 0.6f;

	// Token: 0x04001E6C RID: 7788
	public Material SplitMaterial;

	// Token: 0x04001E6D RID: 7789
	public float SplitMappingTileU = 1f;

	// Token: 0x04001E6E RID: 7790
	public float SplitMappingTileV = 1f;

	// Token: 0x04001E6F RID: 7791
	public bool GUIExpandEvents;

	// Token: 0x04001E70 RID: 7792
	public float EventDetachMinMass = 1f;

	// Token: 0x04001E71 RID: 7793
	public float EventDetachMinVelocity = 1f;

	// Token: 0x04001E72 RID: 7794
	public float EventDetachExitForce;

	// Token: 0x04001E73 RID: 7795
	public float EventDetachUpwardsModifier;

	// Token: 0x04001E74 RID: 7796
	public AudioClip EventDetachSound;

	// Token: 0x04001E75 RID: 7797
	public FracturedObject.PrefabInfo[] EventDetachPrefabsArray;

	// Token: 0x04001E76 RID: 7798
	public string EventDetachCollisionCallMethod = string.Empty;

	// Token: 0x04001E77 RID: 7799
	public GameObject EventDetachCollisionCallGameObject;

	// Token: 0x04001E78 RID: 7800
	public float EventDetachedMinLifeTime = float.PositiveInfinity;

	// Token: 0x04001E79 RID: 7801
	public float EventDetachedMaxLifeTime = float.PositiveInfinity;

	// Token: 0x04001E7A RID: 7802
	public float EventDetachedOffscreenLifeTime = float.PositiveInfinity;

	// Token: 0x04001E7B RID: 7803
	public float EventDetachedMinMass = 1f;

	// Token: 0x04001E7C RID: 7804
	public float EventDetachedMinVelocity = 1f;

	// Token: 0x04001E7D RID: 7805
	public int EventDetachedMaxSounds = 5;

	// Token: 0x04001E7E RID: 7806
	public AudioClip[] EventDetachedSoundArray;

	// Token: 0x04001E7F RID: 7807
	public int EventDetachedMaxPrefabs = 5;

	// Token: 0x04001E80 RID: 7808
	public FracturedObject.PrefabInfo[] EventDetachedPrefabsArray;

	// Token: 0x04001E81 RID: 7809
	public string EventDetachedCollisionCallMethod = string.Empty;

	// Token: 0x04001E82 RID: 7810
	public GameObject EventDetachedCollisionCallGameObject;

	// Token: 0x04001E83 RID: 7811
	public AudioClip EventExplosionSound;

	// Token: 0x04001E84 RID: 7812
	public int EventExplosionPrefabsInstanceCount = 10;

	// Token: 0x04001E85 RID: 7813
	public FracturedObject.PrefabInfo[] EventExplosionPrefabsArray;

	// Token: 0x04001E86 RID: 7814
	public AudioClip EventImpactSound;

	// Token: 0x04001E87 RID: 7815
	public FracturedObject.PrefabInfo[] EventImpactPrefabsArray;

	// Token: 0x04001E88 RID: 7816
	public string EventDetachedAnyCallMethod = string.Empty;

	// Token: 0x04001E89 RID: 7817
	public GameObject EventDetachedAnyCallGameObject;

	// Token: 0x04001E8A RID: 7818
	public bool GUIExpandSupportPlanes;

	// Token: 0x04001E8B RID: 7819
	public int RandomSeed;

	// Token: 0x04001E8C RID: 7820
	public float DecomposePreview;

	// Token: 0x04001E8D RID: 7821
	public bool AlwaysComputeColliders = true;

	// Token: 0x04001E8E RID: 7822
	public bool ShowChunkConnectionLines;

	// Token: 0x04001E8F RID: 7823
	public bool ShowChunkColoredState = true;

	// Token: 0x04001E90 RID: 7824
	public bool ShowChunkColoredRandomly;

	// Token: 0x04001E91 RID: 7825
	public bool SaveMeshDataToAsset;

	// Token: 0x04001E92 RID: 7826
	public string MeshAssetDataFile = string.Empty;

	// Token: 0x04001E93 RID: 7827
	public bool Verbose;

	// Token: 0x04001E94 RID: 7828
	public bool IntegrateWithConcaveCollider;

	// Token: 0x04001E95 RID: 7829
	public FracturedObject.ECCAlgorithm ConcaveColliderAlgorithm;

	// Token: 0x04001E96 RID: 7830
	public int ConcaveColliderMaxHulls = 1;

	// Token: 0x04001E97 RID: 7831
	public int ConcaveColliderMaxHullVertices = 64;

	// Token: 0x04001E98 RID: 7832
	public int ConcaveColliderLegacySteps = 1;

	// Token: 0x04001E99 RID: 7833
	[HideInInspector]
	public List<SupportPlane> ListSupportPlanes = new List<SupportPlane>();

	// Token: 0x04001E9A RID: 7834
	[HideInInspector]
	public List<FracturedChunk> ListFracturedChunks = new List<FracturedChunk>();

	// Token: 0x04001E9B RID: 7835
	[HideInInspector]
	public GameObject SingleMeshObject;

	// Token: 0x04001E9C RID: 7836
	[HideInInspector]
	public bool IsUsingSingleMeshObjectDraw;

	// Token: 0x04001E9D RID: 7837
	[HideInInspector]
	public float DecomposeRadius = 1f;

	// Token: 0x04001E9E RID: 7838
	public static Color GizmoColorSupport = new Color(0f, 0f, 0.2f, 0.7f);

	// Token: 0x04001E9F RID: 7839
	public static Color GizmoColorNonSupport = new Color(0.3f, 0f, 0f, 0.7f);

	// Token: 0x04001EA0 RID: 7840
	private bool m_bCheckDetachNonSupportedChunkds;

	// Token: 0x04001EA1 RID: 7841
	private bool m_bExploded;

	// Token: 0x04001EA2 RID: 7842
	private bool m_bDetached;

	// Token: 0x04001EA3 RID: 7843
	private float[] m_afFreeChunkSoundTimers;

	// Token: 0x04001EA4 RID: 7844
	private float[] m_afFreeChunkPrefabTimers;

	// Token: 0x04001EA5 RID: 7845
	private Material m_GizmosMaterial;

	// Token: 0x0200042E RID: 1070
	public enum EFracturePattern
	{
		// Token: 0x04001EA7 RID: 7847
		BSP,
		// Token: 0x04001EA8 RID: 7848
		Voronoi
	}

	// Token: 0x0200042F RID: 1071
	public enum ColliderType
	{
		// Token: 0x04001EAA RID: 7850
		Collider,
		// Token: 0x04001EAB RID: 7851
		Trigger
	}

	// Token: 0x02000430 RID: 1072
	[Serializable]
	public class PrefabInfo
	{
		// Token: 0x06001E43 RID: 7747 RVA: 0x000C0E6E File Offset: 0x000BF06E
		public PrefabInfo()
		{
			this.MinLifeTime = float.PositiveInfinity;
			this.MaxLifeTime = float.PositiveInfinity;
			this.GameObject = null;
		}

		// Token: 0x04001EAC RID: 7852
		public float MinLifeTime = float.PositiveInfinity;

		// Token: 0x04001EAD RID: 7853
		public float MaxLifeTime = float.PositiveInfinity;

		// Token: 0x04001EAE RID: 7854
		public GameObject GameObject;
	}

	// Token: 0x02000431 RID: 1073
	public enum ECCAlgorithm
	{
		// Token: 0x04001EB0 RID: 7856
		Fast,
		// Token: 0x04001EB1 RID: 7857
		Normal,
		// Token: 0x04001EB2 RID: 7858
		Legacy
	}
}
